/**
 * Created by shidaiapp on 2017/9/29.
 */

export const init = (tiyData) => {
  tiyData.tData.dailyStatisticFailList.splice(0, tiyData.tData.dailyStatisticFailList.length);
  tiyData.tPage.total = 1;
  tiyData.tPage.startIndex = 0;
  tiyData.tPage.stepNumber = 60;
  tiyData.tPage.currentPage = 1;
  tiyData.tParams.searchParams.date = "";
};

/**
 * 从服务器请求列表
 * @param self
 * @param tiyData
 * @returns {Array}
 */
export const searchService = (self, tiyData) => {
  self.$Spin.show();
  self.$apiAnalysis.dailyStatisticFailList({
    "pageSize": tiyData.tPage.stepNumber,
    "pageNum": tiyData.tPage.currentPage
  }).then(function (response) {
    self.$Spin.hide();
    if (response.success) {
      let dataPage = response.result;
      tiyData.tPage.total = dataPage.total;
      tiyData.tData.dailyStatisticFailList.splice(0, tiyData.tData.dailyStatisticFailList.length);
      dataPage.list.forEach(
        function (item) {
          tiyData.tData.dailyStatisticFailList.push(item);
        }
      );
    } else {
      self.$Message.error(response.errorMessage);
    }
  });
};

/**
 * 重新生成每日数据
 * @param self
 * @param tiyData
 * @returns {Array}
 */
export const reStatisticData = (self, tiyData, failId) => {
  self.$Spin.show();
  self.$apiAnalysis.reStatisticData({
    "failId": failId
  }).then(function (response) {
    self.$Spin.hide();
    if (response.success) {
      self.$Message.success("重新生成每日数据。");
      searchService(self, tiyData);
    } else {
      self.$Message.error(response.errorMessage);
    }
  });
};
